package com.alinesno.cloud.initializr.starter.cicd.deploy.k8s;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;

/**
 * k8s api接口客户端 ( kubectl proxy --port=42091 &)
 * 
 * @author WeiXiaoJin
 * @date 2021年6月25日 下午8:28:47
 */
@Service
public class K8sApiClient {

	@Autowired
	private ApiProperties apiProperties ; 

	/**
	 * 获取到k8s实例
	 * 
	 * @return
	 * @throws IOException
	 */
	public KubernetesClient instance() {

		Config config = new ConfigBuilder().withMasterUrl(apiProperties.getUrl()).build();
		KubernetesClient client = new DefaultKubernetesClient(config);

		return client;
	}

}
